package com.seashell.reader;

import com.seashell.exception.ExcelReadException;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;

/**
 * <ul>
 * <li>文件名称 : com.seashell.reader.XslxReader
 * </li>
 * <li>版权所有 : 版权所有(C)2016-2020</li>
 * <li>公 司 : CST</li>
 * <li>创建时间 : 2017/1/17</li>
 * <li>修改记录 : </li>
 * </ul>
 * 类说明：excel2007及以上版本读取
 *
 * @author Allen
 * @version 1.0
 */
public class XslxReader implements IExcelReader {

    public File read(String excelFilePath,Boolean includeFirstRow) {

        File file = new File(excelFilePath);
        if(!file.exists()){
            throw new ExcelReadException("file:"+excelFilePath+" not exist");
        }
        try{
            XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(file));
            for(Iterator<XSSFSheet> iterator = workbook.iterator();iterator.hasNext();){
                XSSFSheet next = iterator.next();
                //最后一行行号
                int lastRowNum = next.getLastRowNum();
                int startRow = includeFirstRow ? 0 : 1;
                if(startRow >= lastRowNum){
                    continue;
                }
                for (int i = startRow; i < lastRowNum; i++) {

                }


            }

        } catch (IOException e) {
            throw new ExcelReadException(e);
        }
        return null;
    }
}